<template>
  <el-breadcrumb separator="/">
    <transition-group name="breadcrumb">
      <el-breadcrumb-item
        v-for="(item, index) in breadcrumb"
        :key="item.meta.title"
      >
        <span class="no-redict" v-if="index === breadcrumb.length - 1">{{
          getMenuTitle(item.meta.title)
        }}</span>
        <span v-else class="redict" @click="onLinkClick(item)">{{
          getMenuTitle(item.meta.title)
        }}</span>
      </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>
<script setup>
import { ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useStore } from 'vuex'
import { getMenuTitle } from '@/utils/i18n'
const route = useRoute()
const breadcrumb = ref([])
const getBreadcrumb = () => {
  breadcrumb.value = route.matched.filter(
    (item) => item.meta.title && item.meta.icon
  )
}
watch(
  route,
  () => {
    getBreadcrumb()
  },
  {
    immediate: true
  }
)
const store = useStore()
const linkHoverColor = ref(store.getters.cssVar.menuBg)
const router = useRouter()
const onLinkClick = (item) => {
  router.push(item.path)
}
</script>
<style lang="scss" scoped>
.no-redict {
  color: #97a8be;
}
.redict {
  color: #666;
  cursor: pointer;
}
.redict:hover {
  color: v-bind(linkHoverColor);
}
</style>
